package com.megvii.koala.tv.data;

import com.megvii.koala.data.UrlMaker;
import com.megvii.koala.data.manager.KoalaBeanManager;

/**
 * Created by linyue on 16/1/25.
 */
public class ThemeManager extends KoalaBeanManager<ThemeBean> implements UrlMaker
{
    private ServerManager serverManager;

    public ThemeManager(ServerManager serverManager)
    {
        super();
        this.serverManager = serverManager;
        setUrlMaker(this);
    }

    @Override
    protected void update(ThemeBean bean, boolean sortAndIndex)
    {
        bean.id = bean.theme;
        bean.screenshot = makeUrl(bean.screenshot);
        super.update(bean, sortAndIndex);
    }

    public String makeUrl(String relativeUrl)
    {
        if (relativeUrl == null || relativeUrl.isEmpty())
        {
            return null;
        }
        if (relativeUrl.startsWith("http") || relativeUrl.startsWith("file"))
        {
            return relativeUrl;
        }
        else
        {
            return serverManager.getAddress() + relativeUrl;
        }
    }
}
